package com.zz.tijian.handle.mq;

import com.zz.tijian.handle.mq.dto.PayMQDto;
import com.zz.tijian.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class PayConsumer {


    @Autowired
    private OrdersService ordersService;

    /*
    正常处理支付队列
     */
    @RabbitListener(queues = RabbitMQConfig.PAY_QUEUE)
    public void handleRefundMessage(PayMQDto payMQDto) {
        try {
            ordersService.processPay(payMQDto);
        } catch (Exception e) {
            // 处理失败，手动抛出异常，让消息进入死信队列
            throw new RuntimeException("Pay processing failed");
        }
    }

}
